package com.gree.flowable.app.tools.utils;

import com.gree.common.utils.FtpUtil;
import org.nutz.dao.Dao;
import org.nutz.dao.Sqls;
import org.nutz.dao.entity.Record;
import org.nutz.dao.sql.Sql;

import java.util.List;

public class Ftp {
    // ftp服务器地址
    public static String hostname = "";
    // ftp服务器端口号默认为null
    public static Integer port = null;
    // ftp登录账号
    public static String username = "";
    // ftp登录密码
    public static String password = "";

    static {
        try {
            Dao dao = SpringContextUtil.getBean(Dao.class);
            Sql sql = Sqls.create("	select upad,usid,pswd from smcom06 where ttyp = 1");
            sql.setCallback(Sqls.callback.entities());
            sql.setEntity(dao.getEntity(Record.class));
            List<Record> list_upfile = dao.execute(sql).getList(Record.class);
            hostname = list_upfile.get(0).getString("upad");
            username = list_upfile.get(0).getString("usid");
            password = list_upfile.get(0).getString("pswd");

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static final FtpUtil newInstance() {
        FtpUtil ftp = new FtpUtil(hostname, username, password);
        return ftp;
    }
}
